#!/usr/bin/env bash
################################################################################
# Test objective: check if we can send packets through ephimeral VALE ports
#                 while using extra buffers.
# Operations:
# 1) send from vale0:v0 using extra buffers, and check that both, vale0:v1 and
#    vale0:v2, receive.
################################################################################
source test_lib

parse_send_recv_arguments "$@"
verbosity="${verbosity:-}"
fill="${fill:-c}"
len="${len:-274}"
num="${num:-1}"
seq="${seq:-}"

e_buf_num="${e_buf_num:-12}"

# Pre-opening interface that will be needed. This is needed to avoid a race
# condition between the sending and receiving ports.
$FUNCTIONAL $verbosity -i "vale0:v1"
check_success $? "pre-open vale0:v1"
$FUNCTIONAL $verbosity -i "vale0:v2"
check_success $? "pre-open vale0:v2"

# v0 ---> v1, v2
$FUNCTIONAL $verbosity -i "vale0:v1" -r "${len}:${fill}:${num}" $seq &
p1=$!
$FUNCTIONAL $verbosity -i "vale0:v2" -r "${len}:${fill}:${num}" $seq &
p2=$!
$FUNCTIONAL $verbosity -I "vale0:v0" -t "${len}:${fill}:${num}" -e "$e_buf_num" $seq
e3=$?
wait $p1
e1=$?
wait $p2
e2=$?
check_success $e1 "receive-${num} vale0:v1"
check_success $e2 "receive-${num} vale0:v2"
check_success $e3 "send-${num} vale0:v0"
